package km.TestWebView;

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class TestWebView extends Activity {

	static final String url = "http://www.google.co.kr";

	
	private WebView webview;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);  
		setContentView(R.layout.main);
		
		
		webview = (WebView) findViewById(R.id.webview);
		webview.getSettings().setJavaScriptEnabled(true);
		webview.setWebViewClient(new TestWebViewClient());

		webview.loadUrl(url);
		setTitle(url);
	}

	@Override
	public void onBackPressed() {
		if ( webview.canGoBack() )
			webview.goBack();
		else 
			super.onBackPressed();
	}
	
	private class TestWebViewClient extends WebViewClient {
		@Override
		public boolean shouldOverrideUrlLoading(WebView view, String url) {
			view.loadUrl(url);
			TestWebView.this.setTitle(url);
			return true;
		}

		@Override
		public void onPageFinished(WebView view, String url) {
			setProgressBarIndeterminateVisibility(false);
		}
		@Override
		public void onPageStarted(WebView view, String url, Bitmap favicon) {
			setProgressBarIndeterminateVisibility(true);
			super.onPageStarted(view, url, favicon);
		}
	}
	

	
	@Override
	public boolean onPrepareOptionsMenu(Menu menu) {
		startSearch(null, false, null, true); 
		Log.e("djrain","TestWebView onMenuOpened:");
		return super.onPrepareOptionsMenu(menu);
	}
}
